package ControlLayer;
import java.util.ArrayList;
import ModelLayer.*;

//model layer package has to be imported

/**
 * Controller class for the address book
 * 
 * @author (kbh) 
 * @version (2005.03.31)
 * (FEN): 2006.03.21: Some changes to the architecture in order to assure layering
 *                    and loose coupling
 * (KBH): 2010.04.09 : Changed comments
 */
public class AddressCtr
{
    private Person _p;
    private AddressBook _addrB;

    public AddressCtr()
    {
        _p = null;
        _addrB = AddressBook.getInstance();
    }
    
    public void createPerson(long id, String name, String address, String zip, String city, String phone)
    {   
       _p = new Person(id, name, address, zip, city, phone);
       _addrB.addPerson(_p);
    }
    
    public void removePerson(long id)
    {

           _addrB.deletePerson(id);
          }
    
    public void updatePerson(long id, String name, String address, String zip, String city, String phone)
    {
        _addrB.updatePerson(id, name, address, zip, city, phone);
    }
    
    public String getPerson(long id)
    {
        Person p = _addrB.getPerson(id);
        
        String person = "ID: " +p.getID() + "\n";
        person += "Name: " + p.getName() + "\n";
        person += "Address: " + p.getAddress() + "\n";
        person += "Postal code: " + p.getZip() + "\n";
        person += "City: " + p.getCity() + "\n";
        person += "Phone: " + p.getPhone() + "\n";
        
        return person;
    }
    
    public String listAllPersons()
    {
        ArrayList<Person> personP = _addrB.listAllPersons();
        String persons = "";
        
        for (Person p : personP)
        {
            persons += "ID: " +p.getID() + "\n";
            persons += "Name: " + p.getName() + "\n";
            persons += "Address: " + p.getAddress() + "\n";
            persons += "Postal code: " + p.getZip() + "\n";
            persons += "City: " + p.getCity() + "\n";
            persons += "Phone: " + p.getPhone() + "\n\n";
        }
        
        return persons;
    }
}
